package com.lucker.controller;

import com.lucker.common.util.StringUtil;
import com.lucker.framework.constant.ResponseBaseModel;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class UserController extends BaseController {

    @RequestMapping(value = "/admin/login",method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity<?> adminLogin(@RequestBody Map<String,Object> user, HttpSession session) {
        String username = (String) user.get("username");
        String password = (String) user.get("password");
        if (!StringUtil.isNotBlank(username) || !StringUtil.isNotBlank(password)) {
            return new ResponseEntity<>(new ResponseBaseModel(1,"用户密码不能为空!"), HttpStatus.OK);
        }
        if (username.equals("root") && password.equals("root")) {
            session.setAttribute("username",username);
            return new ResponseEntity<>(new ResponseBaseModel(0,"登陆成功!"), HttpStatus.OK);
        } else {
            return new ResponseEntity<>(new ResponseBaseModel(1,"用户密码错误!"), HttpStatus.OK);
        }

    }
}
